<?php
namespace  Teachers\Controller;
use Think\Controller;
/**
 * 院系介绍
 * 
 * */
class DepartmentsController extends CommonController
{
	/**
	 * 增加院系
	 * */
	public function __construct()
	{
		parent::__construct();
		$this->Departments_type=I('get.departments_type');
	}
	public function addDepartments(){
		$school_id=$this->showschoolID();
		$departments_name=I('post.departments_name');
		if($school_id && $departments_name){
			$data=array(
				'school_id'	=>	$school_id,
				'name'		=>	$departments_name,
				'type'		=>	I('post.departments_type'),
				'content'	=>	I('post.departments_content')
			);
			$departments=M('SchoolDepartments');
			$departments_id=$departments->add($data);
			if(!$departments_id){
				$this->error('新增失败！');
			}
			$params['departments_type']=I('post.departments_type');
			$this->redirect('Teachers/Departments/index',$params, 0, '页面跳转中...');
		}
		
	
	}
	
	/**
	 * 查询高校院系
	 * 
	 * */
	public function index(){
		$school_id=$this->showschoolID();
		if($school_id){
			$map['school_id']=$school_id;
			$map['type']=I('get.departments_type');
			$departments=M('school_departments');
			$departments_data=$departments->where($map)->select();
			$this->assign("departments_data",$departments_data);
			$this->assign("school_id",$school_id);
			$this->assign("departments_type",$map['type']);
			$this->display();
		}else{
			$this->error('传入高校参数错误！');
		}
	}
	
	
	/**
	 * 修改高校院系
	 *  
	 *  
	 * */
	public function updateDepartments(){
		$school_id=$this->showschoolID();
		$departments_id=I('post.departments_id');
		if($school_id && $departments_id){
			$data=array(
				'name'		=>	I('post.departments_name'),
				'content'	=>	I('post.departments_content')
			);
			$map['school_id']=$school_id;
			$map['departments_id']=$departments_id;
			$departments=M('school_departments');
			$departments_data=$departments->where($map)->save($data);
		}
	}
	
	
	/**
	 * 删除高校院系
	 * 
	 * */
	public function deleteDepartments(){
		$school_id=$this->showschoolID();
		$departments_id=I('post.departments_id');
	if($school_id && $departments_id){
			$map['school_id']=$school_id;
			$map['departments_id']=$departments_id;
			$departments=M('school_departments');
			$flag=$departments->where($map)->delete();
			if(!$flag){
				$this->error('删除失败！');				
			}
		}
	}
	



}